package com.tong.controller;

import com.tong.pojo.Books;
import com.tong.pojo.Users;
import com.tong.service.book.BookService;
import com.tong.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    @Qualifier("UserServiceImpl")
    private UserService userService;

    @RequestMapping("/allUser")
    public String allUser(Model model) {
        List<Users> list = userService.queryAllUser();
        model.addAttribute("list", list);
        return "user/allUser";
    }

    @RequestMapping("/toAddUser")
    public String toAddUser() {
        return "user/addUser";
    }

    @RequestMapping("/addUser")
    public String addBook(Users users) {
        userService.addUser(users);
        return "redirect:/user/allUser";
    }

    @RequestMapping("/deleteUser/{username}")
    public String deleteUser(@PathVariable("username") String username){
        userService.deleteUser(username);
        return "redirect:/user/allUser";
    }
}